module HelperMethods
  module Request
    %w(get post patch delete options head).each do |verb|
      define_method(verb) do |path, query: nil, body: nil, &block|
        with_api(Server) do
          send "#{verb}_request", path: path,
               head: {'Content-Type' => 'application/json'},
               query: query,
               body: (body && body.to_json) do |client|
            status = client.response_header.status
            response = MultiJson.load client.response
            block.call response, status
          end
        end
      end
    end
  end
end